import { fileURLToPath, URL } from 'node:url'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import { createHtmlPlugin } from 'vite-plugin-html'
import { viteMockServe } from 'vite-plugin-mock'
import { configDefaults } from 'vitest/config'
// import reactivityTransform from '@vue-macros/reactivity-transform'
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  server: {
    port: 80,
    host: true
  },
  test: {
    globals: true,
    environment: 'happy-dom', // 使用 happy-dom 作为测试环境
    setupFiles: './test/setup.ts', // 配置文件路径
    include: [
      'src/components/tests/**/*.test.ts',
      'src/components/test/**/*.test.ts',
      'src/utils/test/**/*.test.ts'
    ],
    exclude: [...configDefaults.exclude, 'tests/e2e/*']
  },
  plugins: [
    createHtmlPlugin(),
    vue(),
    viteMockServe({
      mockPath: './src/mock',
      localEnabled: true,
      prodEnabled: false // 生产环境禁用 mock
    }),
    Components({
      dts: false,
      resolvers: [VantResolver({ importStyle: false })]
    }),
    createSvgIconsPlugin({
      // 指定图标文件夹，绝对路径（NODE代码）
      // eslint-disable-next-line no-undef
      iconDirs: [path.resolve(process.cwd(), 'src/icons')]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
